<template>
	<view class="flex-col page">
		<view class="flex-col">
			<view class="flex-col section_1">
				<view class="justify-between group_2">
					<text class="text_1">发票类型</text>
					<text class="text_2">电子发票</text>
				</view>
			</view>
			<view class="flex-col items-start text-wrapper"><text class="text_3">发票信息</text></view>
			<view class="justify-between group_66 group_11">
				<text class="text_44">抬头类型</text>
				<view class="text_55">
					<radio-group name="radio" @change="change">
						<label>
							<radio value="0" style="transform:scale(0.8)" :checked="form.openType==0" /><text
								class="u-m-r-40">个人</text>
						</label>
						<label>
							<radio value="1" style="transform:scale(0.8)" :checked="form.openType==1" />
							<text>企业</text>
						</label>
					</radio-group>
				</view>
			</view>
			<view class="justify-between group_66 group_11">
				<image
					src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/617a2ca7e4f1450011362b37/62b127f6d029820011531bae/16557837641414645292.png"
					class="image_5" />
				<text class="text_44">发票抬头</text>
				<view class="text_55"><text class="text_9">
						<u--input v-model="form.rise" placeholder="发票抬头不能为空" maxlength="64" border="none"
							inputAlign="right">
						</u--input>
					</text></view>
			</view>
			<view class="justify-between group_66 group_11" v-if="form.openType==1">
				<image
					src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/617a2ca7e4f1450011362b37/62b127f6d029820011531bae/16557837641414645292.png"
					class="image_5" />
				<text class="text_44">公司税号</text>
				<view class="text_55"><text class="text_9">
						<u--input v-model="form.dutyParagraph" placeholder="企业单位税号不能为空" maxlength="20" border="none"
							inputAlign="right"></u--input>
					</text></view>
			</view>
			<view class="justify-between group_66 group_11">
				<text class="text_44">设置为默认抬头</text>
				<view class="text_55">
					<checkbox-group style="transform:scale(0.8)" class="uni-list" @change="defaultChange">
						<label>
							<view>
								<checkbox value="1" v-model="form.isDefault" :checked="form.isDefault==1">
								</checkbox>
							</view>
						</label>
					</checkbox-group>
				</view>
			</view>
			<view class="justify-between group_66 group_11 u-m-t-10 u-m-b-10">
				<text class="text_44">发票内容</text>
				<view class="text_55"><text class="text_6">
						<u--input v-model="form.content" placeholder="发票内容" border="none" maxlength="30"
							inputAlign="right">
						</u--input>
					</text></view>
			</view>
			<view class="justify-between group_66 group_11">
				<image
					src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/617a2ca7e4f1450011362b37/62b127f6d029820011531bae/16557837641414645292.png"
					class="image_5" />
				<text class="text_44">联系方式</text>
				<view class="text_55"><text class="text_6">
						<u--input type="number" v-model="form.phone" placeholder="请输入联系方式" border="none" maxlength="11"
							inputAlign="right">
						</u--input>
					</text></view>
			</view>
			<view class="justify-between group_66 group_11">
				<text class="text_44">电子邮箱</text>
				<view class="text_55"><text class="group_7 text_15">
						<u--input v-model="form.email" placeholder="请输入电子邮箱" border="none" maxlength="20"
							inputAlign="right">
						</u--input>
					</text></view>
			</view>

		</view>
		<view class="flex-col items-center text-wrapper_1" @click="submit"><text class="text_16">提交</text></view>
	</view>
</template>

<script>
	export default {
		onLoad(option) {
			if (option.hasOwnProperty('orderid')) {
				this.getDefault(option.orderid);
				// this.getIsDefault(option.orderid);
				this.orderid = option.orderid;
			}
		},
		components: {},
		data() {
			return {
				orderid: '',
				value: '',
				current: '',
				checked: true,
				bill: {},
				checkboxItems: [{
					name: 'USA',
					value: ''
				}, ],
				form: {
					rise: '',
					isDefault: 0,
					dutyParagraph: '',
					openType: 0,
					content: '',
					phone: '',
					email: '',
					invoicingTypeId: 0,
				},

			};
		},
		methods: {

			radioCheck(index) {
				const radio = this.radio;
				this.radio.forEach((item => {
					radio.isCheck = true
				}))
				if (this.radioValue == 1) {
					this.radioValue = 0
				} else {
					this.radioValue = 1;
					this.radioValue = 0;
				}
				console.log(this.radioValue)
			},

			submit() {
				this.form.ordersId = this.orderid;
				if (!this.form.rise) {
					this.$u.toast('发票抬头不能为空');
					return;
				}

				if (this.form.openType == 1 && !this.form.dutyParagraph) {
					this.$u.toast('请输入公司税号');
					return;
				}

				if (this.form.phone == '') {
					this.$u.toast('请输入手机号');
					return;
				} else {
					if (!uni.$u.test.mobile(this.form.phone)) {
						this.$u.toast('手机号码格式错误');
						return;
					}
				}
				if (this.form.email) {
					if (!uni.$u.test.email(this.form.email)) {
						this.$u.toast('邮箱格式错误');
						return;
					}
				} else {
					console.log("无需输入邮箱");
				}

				uni.setStorageSync('bill', this.form);

				// console.log("税号：----"+form.dutyParagraph);
				this.go('/pages/my/bill/confirmBill?orderid=' + this.orderid)
				// this.$http('bill.invoicing',this.form).then(r=>{
				//  console.log(r);
				// });
			},
			getDefault(orderid) {
				this.$http('bill.check', {
					ordersId: orderid
				}).then(r => {
					if (r.code == 200) {
						this.bill = r.data;
						this.form.rise = r.data.defaultInvoicList[0].rise;
						console.log(666, r.data.defaultInvoicList[0].rise);
						this.form.isDefault = r.data.defaultInvoicList[0].isDefault;
						this.form.dutyParagraph = r.data.dutyParagraph;
					}
				});
			},


			change(event) {
				this.form.openType = event.detail.value;

			},
			defaultChange(event) {
				console.log(event);
				// this.form.isDefault = event.detail.value[0];

				if (event.detail.value.length == 0) {
					this.form.isDefault = 0
				} else {
					this.form.isDefault = 1
				}
				console.log(this.form.isDefault);
				// if (event.detail.value) {
				// 	event.checked == false;
				// } else {
				// 	event.checked == true;
				// }

				// if (event) {
				// 	this.form.isDefault = event.detail.value[1];
				// } else {
				// 	
				// }


				// event.detail.value.forEach(item => {
				// 	console.log('考核表', item);
				// 	if (item == '') {
				// 		this.form.isDefault = 1;

				// 		console.log(this.form);

				// 	} else {
				// 		this.form.isDefault = 0;
				// 		console.log(this.form);
				// 	}
				// })


				// console.log(666, event.detail.value);

			}
		},
	};
</script>

<style lang="scss">
	.row-right {
		margin-left: 90px;
	}

	.list-item {
		padding: 0 15px 15px 16px;
		background-color: #ffffffff;
	}

	.group_3 {
		padding: 15px 0px 15px 10px;
		display: flex;
		height: 100%;
		align-items: center;
		// border-bottom: solid 0.5px #eeeeee;
	}

	.image_9 {
		margin-top: 4px;
		width: 18px;
		height: 18px;
	}

	.group_44 {
		padding: 15px 0 20px 0px;
		display: flex;
		height: 100%;
		align-items: center;
		border-top: solid 0.5px #eeeeee;

	}

	.group_12 {
		padding: 15px 0 0px 0px;
	}

	.text_4 {
		color: #333333;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
		display: flex;
		height: 100%;
		align-items: center;
	}

	.text_6 {
		color: #333333;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
	}

	.group_5 {
		// padding-top: 15px;
		padding: 20rpx 0 10rpx 0;
		border-top: solid 0.5px #eeeeee;
	}

	.group_6 {
		// padding-top: 15px;
		padding: 20rpx 0 25rpx 0;
		border-top: solid 0.5px #eeeeee;
	}

	.group_5-1 {
		margin: 0 6.5px;
	}

	.group_7 {
		margin-top: 20.5px;
		padding-left: 10px;
		padding-top: 15px;
		// border-top: solid 0.5px #eeeeee;
	}

	.group_9 {
		margin-top: 5.5px;
		// border-top: solid 0.5px #eeeeee;
	}

	.page {
		padding-bottom: 20px;
		background-color: #f6f7f9;
		width: 100%;
		overflow-y: auto;
		overflow-x: hidden;
		min-height: 100vh;
	}

	.text-wrapper_1 {
		margin: 0px 16px 0;
		margin-top: 100rpx;
		// padding: 9.5px 0 15.5px;
		height: 88rpx;
		background-color: #1d6aff;
		border-radius: 22px;
	}

	.section_1 {
		background-color: #ffffffff;
	}

	.text-wrapper {
		padding: 12px 0 12px;
		background-color: #e9efffff;
	}

	.text_16 {
		color: #ffffff;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
		height: 100%;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.group_1 {
		padding: 26.5px 15.75px 15.5px;
		border-bottom: solid 0.5px #eeeeee;
		position: relative;
	}

	.group_2 {
		padding: 14.5px 16px 21px 26px;
	}

	.text_3 {
		margin-left: 26px;
		color: #1d6aff;
		font-weight: 550;
		font-size: 14px;
		font-family: '.AppleSystemUIFont';
		line-height: 16.5px;
	}

	.section_3 {
		padding: initial;
		padding-left: 16px;
		padding-right: 15px;
	}

	.list-item:last-of-type {
		margin-top: 10px;
	}

	.image {
		position: absolute;
		left: 15.75px;
		bottom: 13.25px;
		width: 10.5px;
		height: 18px;
	}

	.text {
		color: #000000;
		font-size: 18px;
		font-family: '.AppleSystemUIFont';
		line-height: 21.5px;
	}

	.text_1 {
		color: #202020;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
	}

	.text_2 {
		color: #333333;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
	}

	.group_66 {
		display: flex;
		align-items: center;
		height: 110rpx;
		background-color: #ffffff;
	}

	.group_11 {
		padding: 14.5px 0 14.5px;
		border-bottom: solid 0.5px #eeeeee;
	}

	.text_44 {
		margin-left: 50rpx;
		font-weight: 400;
		color: #333333;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
		color: #000;
	}

	.image_5 {
		position: absolute;
		margin-top: 3px;
		margin-left: 33rpx;
		flex-shrink: 0;
		width: 6px;
		height: 6px;
	}

	.text_55 {
		color: #000000;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
		margin-right: 30rpx;
	}


	.view_1 {
		padding: initial;
	}

	.view_4 {
		padding: 14.5px 0 17.5px;
	}

	.view_5 {
		color: initial;
		font-size: initial;
		font-family: initial;
		line-height: initial;
		// margin-bottom: 3.5px;
	}

	.text_13 {
		margin-top: 3.5px;
	}

	.text_14 {
		padding-top: initial;
		// margin-bottom: 3.5px;
		margin-left: 10rpx;
		color: #202020;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
	}

	.text_15 {
		margin-top: 3.5px;
		padding-left: initial;
		padding-top: initial;
		border-top: initial;
		color: #333333;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
		line-height: 19px;
	}

	.text_9 {
		color: #333333;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
		width: 700rpx;
	}

	.text_10 {
		color: #202020;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
		line-height: 19px;
	}

	.text_11 {
		color: #333333;
		margin-left: 21rpx;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
		line-height: 19px;
	}

	.image_2 {
		margin-top: 10px;
		flex-shrink: 0;
		width: 6px;
		height: 6px;
	}

	.text_12 {
		margin-left: 4px;
		color: #202020;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
	}

	.text_122 {
		margin-left: 10px;
		color: #202020;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
	}


	.image_1 {
		margin-top: 10px;
		flex-shrink: 0;
		width: 6px;
		height: 6px;
	}

	.text_8 {
		margin-left: 4px;
		color: #202020;
		font-size: 16px;
		font-family: '.AppleSystemUIFont';
		/* line-height: 2px; */
	}
</style>
